﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MidwayBattle.Models
{
    class PlacedShip
    {
        public int Type { get; set; }
        public int Life { get; set; }
        public int Owner { get; set; }       
        public int Length { get; set; }

        public int XStart { get; set; }
        public int YStart { get; set; }

        public int Orientation { get; set; }
        public int Status { get; set; }

        public PlacedShip()
        {
            Type = -1;
            Life = -1;
            Owner = -1;
            Length = -1;
            XStart = -1;
            YStart = -1;
            Orientation = -1;
            Status = -1;
        }
        //--------------------------------------------------------------------------------------------------------------------------------------------
        /*
         * 
         * 	  typedef struct PlacedShip
	  {
		  int Type;
		  int Life;
		  int Size;
		  int X;
		  int Y;
		  int Orient;
	  } PlacedShip;
         * 
         * */
        //--------------------------------------------------------------------------------------------------------------------------------------------
        public MidwayBattle.CustomDefines.PlacedShip_Struct ToStructure()
        {
            MidwayBattle.CustomDefines.PlacedShip_Struct ret;
            ret.Type = this.Type;
            ret.Life = this.Life;
            ret.Size = this.Length;
            ret.X = this.XStart;
            ret.Y = this.YStart;
            ret.Orient = this.Orientation;
            return ret;
        }
        //--------------------------------------------------------------------------------------------------------------------------------------------
        public static void InitPlacedShipTab(PlacedShip[] tab, int owner)
        {
            // Rappel: tab contient CustomDefines.SHIP_TOTALAMOUNTPERPLAYER cellules

            int cptTab = 0;

            // Initialisation des données relatives aux porte-avions
            for (int carriersCpt = 0; carriersCpt < CustomDefines.SHIP_CARRIER_AMOUNT; carriersCpt++)
            {
                tab[cptTab] = new PlacedShip();
                tab[cptTab].Type = CustomDefines.SHIP_CARRIER;
                tab[cptTab].Length = CustomDefines.SHIP_CARRIER_SIZE;
                tab[cptTab].Life = CustomDefines.SHIP_CARRIER_SIZE;
                tab[cptTab].Orientation = -1;
                tab[cptTab].Owner = owner;
                tab[cptTab].Status = CustomDefines.SHIP_STATUS_ALIVE;
                tab[cptTab].XStart = -1;
                tab[cptTab].YStart = -1;
                cptTab++;
            }

            // Initialisation des données relatives aux battleships
            for (int battleshipsCpt = 0; battleshipsCpt < CustomDefines.SHIP_BATTLESHIP_AMOUNT; battleshipsCpt++)
            {
                tab[cptTab] = new PlacedShip();
                tab[cptTab].Type = CustomDefines.SHIP_BATTLESHIP;
                tab[cptTab].Length = CustomDefines.SHIP_BATTLESHIP_SIZE;
                tab[cptTab].Life = CustomDefines.SHIP_BATTLESHIP_SIZE;
                tab[cptTab].Orientation = -1;
                tab[cptTab].Owner = owner;
                tab[cptTab].Status = CustomDefines.SHIP_STATUS_ALIVE;
                tab[cptTab].XStart = -1;
                tab[cptTab].YStart = -1;
                cptTab++;
            }

            // Initialisation des données relatives aux croiseurs
            for (int cruisersCpt = 0; cruisersCpt < CustomDefines.SHIP_CRUISER_AMOUNT; cruisersCpt++)
            {
                tab[cptTab] = new PlacedShip();
                tab[cptTab].Type = CustomDefines.SHIP_CRUISER;
                tab[cptTab].Length = CustomDefines.SHIP_CRUISER_SIZE;
                tab[cptTab].Life = CustomDefines.SHIP_CRUISER_SIZE;
                tab[cptTab].Orientation = -1;
                tab[cptTab].Owner = owner;
                tab[cptTab].Status = CustomDefines.SHIP_STATUS_ALIVE;
                tab[cptTab].XStart = -1;
                tab[cptTab].YStart = -1;
                cptTab++;
            }

            // Initialisation des données relatives aux destroyers
            for (int destroyersCpt = 0; destroyersCpt < CustomDefines.SHIP_DESTROYER_AMOUNT; destroyersCpt++)
            {
                tab[cptTab] = new PlacedShip();
                tab[cptTab].Type = CustomDefines.SHIP_DESTROYER;
                tab[cptTab].Length = CustomDefines.SHIP_DESTROYER_SIZE;
                tab[cptTab].Life = CustomDefines.SHIP_DESTROYER_SIZE;
                tab[cptTab].Orientation = -1;
                tab[cptTab].Owner = owner;
                tab[cptTab].Status = CustomDefines.SHIP_STATUS_ALIVE;
                tab[cptTab].XStart = -1;
                tab[cptTab].YStart = -1;
                cptTab++;
            }

            // Initialisation des données relatives aux sous-marins
            for (int submarinesCpt = 0; submarinesCpt < CustomDefines.SHIP_SUBMARINE_AMOUNT; submarinesCpt++)
            {
                tab[cptTab] = new PlacedShip();
                tab[cptTab].Type = CustomDefines.SHIP_SUBMARINE;
                tab[cptTab].Length = CustomDefines.SHIP_SUBMARINE_SIZE;
                tab[cptTab].Life = CustomDefines.SHIP_SUBMARINE_SIZE;
                tab[cptTab].Orientation = -1;
                tab[cptTab].Owner = owner;
                tab[cptTab].Status = CustomDefines.SHIP_STATUS_ALIVE;
                tab[cptTab].XStart = -1;
                tab[cptTab].YStart = -1;
                cptTab++;
            }
        }
        //--------------------------------------------------------------------------------------------------------------------------------------------

        
    }
}
